ποΈGitΠ―ΡΠ°ποΈ
Node / meshtastic / Meshtastic-Android / files / core / service / src / commonMain / kotlin / org / meshtastic / core / service / RadioControllerImpl.kt
Displaying Raw β’ Download
core/service/src/commonMain/kotlin/org/meshtastic/core/service/RadioControllerImpl.kt 4a9f85bf5e54ca8b5089837db2a6b9382d77875f (4a9f85bf) Text, 6.99 KB
T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.core.service
Tff7b72import T7ee787co.touchlab.kermit.Logger
Tff7b72import T7ee787kotlinx.coroutines.CoroutineScope
Tff7b72import T7ee787kotlinx.coroutines.flow.StateFlow
Tff7b72import T7ee787kotlinx.coroutines.flow.combine
Tff7b72import T7ee787kotlinx.coroutines.flow.distinctUntilChanged
Tff7b72import T7ee787kotlinx.coroutines.launch
Tff7b72import T7ee787org.meshtastic.core.common.database.DatabaseManager
Tff7b72import T7ee787org.meshtastic.core.model.ConnectionState
Tff7b72import T7ee787org.meshtastic.core.repository.AdminController
Tff7b72import T7ee787org.meshtastic.core.repository.CommandSender
Tff7b72import T7ee787org.meshtastic.core.repository.MeshDataHandler
Tff7b72import T7ee787org.meshtastic.core.repository.MeshLocationManager
Tff7b72import T7ee787org.meshtastic.core.repository.MeshMessageProcessor
Tff7b72import T7ee787org.meshtastic.core.repository.MeshPrefs
Tff7b72import T7ee787org.meshtastic.core.repository.MessagingController
Tff7b72import T7ee787org.meshtastic.core.repository.NodeController
Tff7b72import T7ee787org.meshtastic.core.repository.NodeManager
Tff7b72import T7ee787org.meshtastic.core.repository.NodeRepository
Tff7b72import T7ee787org.meshtastic.core.repository.NotificationManager
Tff7b72import T7ee787org.meshtastic.core.repository.PacketRepository
Tff7b72import T7ee787org.meshtastic.core.repository.PlatformAnalytics
Tff7b72import T7ee787org.meshtastic.core.repository.QueryController
Tff7b72import T7ee787org.meshtastic.core.repository.RadioConfigRepository
Tff7b72import T7ee787org.meshtastic.core.repository.RadioController
Tff7b72import T7ee787org.meshtastic.core.repository.RadioInterfaceService
Tff7b72import T7ee787org.meshtastic.core.repository.ServiceRepository
Tff7b72import T7ee787org.meshtastic.core.repository.UiPrefs
Tff7b72import T7ee787org.meshtastic.proto.ClientNotification
T8b949e/**
* Platform-agnostic [RadioController] composition root for any target where the service runs in-process (Desktop, iOS,
* or Android in single-process mode).
*
* Rather than implementing every command itself, this class **assembles** four focused collaborators β one per
* sub-interface β and delegates to them via Kotlin interface delegation, mirroring the SDK's layered API design
* ([AdminController] β `AdminApi`, [MessagingController] β `RadioClient.send*`, [NodeController]/[QueryController] β
* `AdminApi`/`TelemetryApi`/`RoutingApi`). When the SDK is adopted, each collaborator becomes a thin adapter and this
* class is the seam where they are wired together.
*
* Only the cross-cutting concerns that don't belong to any single sub-interface live here directly: connection-state
* surfacing, packet-id generation, location provisioning, and device-address switching.
*/
Tf0883e@SuppressTb4b4b4(Ta5d6ff"Ta5d6ffLongParameterListTa5d6ff"Tb4b4b4)
Tff7b72class T56d364RadioControllerImplTb4b4b4(
Tff7b72private Tff7b72val Te6edf3serviceRepositoryTb4b4b4: Te6edf3ServiceRepositoryTb4b4b4,
Te6edf3nodeRepositoryTb4b4b4: Te6edf3NodeRepositoryTb4b4b4,
Tff7b72private Tff7b72val Te6edf3commandSenderTb4b4b4: Te6edf3CommandSenderTb4b4b4,
Tff7b72private Tff7b72val Te6edf3nodeManagerTb4b4b4: Te6edf3NodeManagerTb4b4b4,
Tff7b72private Tff7b72val Te6edf3radioInterfaceServiceTb4b4b4: Te6edf3RadioInterfaceServiceTb4b4b4,
Tff7b72private Tff7b72val Te6edf3locationManagerTb4b4b4: Te6edf3MeshLocationManagerTb4b4b4,
Te6edf3packetRepositoryTb4b4b4: Te6edf3LazyTff7b72<Te6edf3PacketRepositoryTff7b72>Tb4b4b4,
Te6edf3dataHandlerTb4b4b4: Te6edf3LazyTff7b72<Te6edf3MeshDataHandlerTff7b72>Tb4b4b4,
Te6edf3analyticsTb4b4b4: Te6edf3PlatformAnalyticsTb4b4b4,
Tff7b72private Tff7b72val Te6edf3meshPrefsTb4b4b4: Te6edf3MeshPrefsTb4b4b4,
Te6edf3uiPrefsTb4b4b4: Te6edf3UiPrefsTb4b4b4,
Tff7b72private Tff7b72val Te6edf3databaseManagerTb4b4b4: Te6edf3DatabaseManagerTb4b4b4,
Tff7b72private Tff7b72val Te6edf3notificationManagerTb4b4b4: Te6edf3NotificationManagerTb4b4b4,
Tff7b72private Tff7b72val Te6edf3messageProcessorTb4b4b4: Te6edf3LazyTff7b72<Te6edf3MeshMessageProcessorTff7b72>Tb4b4b4,
Te6edf3radioConfigRepositoryTb4b4b4: Te6edf3RadioConfigRepositoryTb4b4b4,
Te6edf3scopeTb4b4b4: Te6edf3CoroutineScopeTb4b4b4,
Tff7b72private Tff7b72val Te6edf3onDeviceAddressChangedTb4b4b4: Tb4b4b4(Tb4b4b4(Tb4b4b4) Tff7b72-Tff7b72> Tffa657UnitTb4b4b4)Tff7b72? Tff7b72= Tff7b72nullTb4b4b4,
Tb4b4b4) Tb4b4b4: Te6edf3RadioControllerTb4b4b4,
Te6edf3AdminController Tff7b72by Te6edf3AdminControllerImplTb4b4b4(Te6edf3commandSenderTb4b4b4, Te6edf3nodeManagerTb4b4b4, Te6edf3radioConfigRepositoryTb4b4b4, Te6edf3scopeTb4b4b4)Tb4b4b4,
Te6edf3MessagingController Tff7b72by Te6edf3MessagingControllerImplTb4b4b4(
Te6edf3commandSenderTb4b4b4,
Te6edf3nodeManagerTb4b4b4,
Te6edf3nodeRepositoryTb4b4b4,
Te6edf3dataHandlerTb4b4b4,
Te6edf3analyticsTb4b4b4,
Te6edf3packetRepositoryTb4b4b4,
Tb4b4b4)Tb4b4b4,
Te6edf3NodeController Tff7b72by Te6edf3NodeControllerImplTb4b4b4(Te6edf3commandSenderTb4b4b4, Te6edf3nodeManagerTb4b4b4, Te6edf3packetRepositoryTb4b4b4, Te6edf3scopeTb4b4b4)Tb4b4b4,
Te6edf3QueryController Tff7b72by Te6edf3QueryControllerImplTb4b4b4(Te6edf3commandSenderTb4b4b4, Te6edf3nodeManagerTb4b4b4, Te6edf3uiPrefsTb4b4b4) Tb4b4b4{
Tff7b72init Tb4b4b4{
T8b949e// Unify per-node databases across transports. When the handshake reports our node number, tell the
T8b949e// DatabaseManager to claim (or merge into) that node's canonical DB, so the same node reached over BLE, TCP,
T8b949e// or USB shares one stored history. Keyed on (address, node) so a second transport for the same node re-fires
T8b949e// even though the node number itself is unchanged.
Te6edf3scopeTb4b4b4.Te6edf3launch Tb4b4b4{
Te6edf3combineTb4b4b4(Te6edf3meshPrefsTb4b4b4.Te6edf3deviceAddressTb4b4b4, Te6edf3nodeManagerTb4b4b4.Te6edf3myNodeNumTb4b4b4) Tb4b4b4{ Te6edf3addressTb4b4b4, Te6edf3nodeNum Tff7b72-Tff7b72> Te6edf3address Te6edf3to Te6edf3nodeNum Tb4b4b4}
Tb4b4b4.Te6edf3distinctUntilChangedTb4b4b4(Tb4b4b4)
Tb4b4b4.Te6edf3collect Tb4b4b4{ Tb4b4b4(Te6edf3_Tb4b4b4, Te6edf3nodeNumTb4b4b4) Tff7b72-Tff7b72> Te6edf3nodeNumTff7b72?.Te6edf3let Tb4b4b4{ Te6edf3databaseManagerTb4b4b4.Te6edf3associateNodeTb4b4b4(Tffa657itTb4b4b4) Tb4b4b4} Tb4b4b4}
Tb4b4b4}
Tb4b4b4}
T8b949e// ββ Connection State ββββββββββββββββββββββββββββββββββββββββββββββββββββ
Tff7b72override Tff7b72val Te6edf3connectionStateTb4b4b4: Te6edf3StateFlowTff7b72<Te6edf3ConnectionStateTff7b72>
Tff7b72getTb4b4b4(Tb4b4b4) Tff7b72= Te6edf3serviceRepositoryTb4b4b4.Te6edf3connectionState
Tff7b72override Tff7b72val Te6edf3clientNotificationTb4b4b4: Te6edf3StateFlowTff7b72<Te6edf3ClientNotification?Tff7b72>
Tff7b72getTb4b4b4(Tb4b4b4) Tff7b72= Te6edf3serviceRepositoryTb4b4b4.Te6edf3clientNotification
Tff7b72override Tff7b72fun Td2a8ffclearClientNotificationTb4b4b4(Tb4b4b4) Tb4b4b4{
Te6edf3serviceRepositoryTb4b4b4.Te6edf3clearClientNotificationTb4b4b4(Tb4b4b4)
Tb4b4b4}
T8b949e// ββ Packet ID & Location ββββββββββββββββββββββββββββββββββββββββββββββββ
Tff7b72override Tff7b72fun Td2a8ffgeneratePacketIdTb4b4b4(Tb4b4b4)Tb4b4b4: Tffa657Int Tff7b72= Te6edf3commandSenderTb4b4b4.Te6edf3generatePacketIdTb4b4b4(Tb4b4b4)
Tff7b72override Tff7b72fun Td2a8ffstartProvideLocationTb4b4b4(Tb4b4b4) Tb4b4b4{
Te6edf3locationManagerTb4b4b4.Te6edf3restartTb4b4b4(Tb4b4b4)
Tb4b4b4}
Tff7b72override Tff7b72fun Td2a8ffstopProvideLocationTb4b4b4(Tb4b4b4) Tb4b4b4{
Te6edf3locationManagerTb4b4b4.Te6edf3stopTb4b4b4(Tb4b4b4)
Tb4b4b4}
T8b949e// ββ Device Address ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Tff7b72override Tff7b72suspend Tff7b72fun Td2a8ffsetDeviceAddressTb4b4b4(Te6edf3addressTb4b4b4: Tffa657StringTb4b4b4) Tb4b4b4{
Te6edf3switchDeviceTb4b4b4(Te6edf3addressTb4b4b4)
Te6edf3radioInterfaceServiceTb4b4b4.Te6edf3setDeviceAddressTb4b4b4(Te6edf3addressTb4b4b4)
Te6edf3onDeviceAddressChangedTff7b72?.Te6edf3invokeTb4b4b4(Tb4b4b4)
Tb4b4b4}
Tff7b72private Tff7b72suspend Tff7b72fun Td2a8ffswitchDeviceTb4b4b4(Te6edf3deviceAddrTb4b4b4: Tffa657StringTb4b4b4) Tb4b4b4{
Tff7b72val Te6edf3currentAddr Tff7b72= Te6edf3meshPrefsTb4b4b4.Te6edf3deviceAddressTb4b4b4.Te6edf3value
Tff7b72if Tb4b4b4(Te6edf3deviceAddr Tff7b72!Tff7b72= Te6edf3currentAddrTb4b4b4) Tb4b4b4{
Te6edf3LoggerTb4b4b4.Te6edf3i Tb4b4b4{ Ta5d6ff"Ta5d6ffDevice address changed, switching database and clearing node DBTa5d6ff" Tb4b4b4}
Te6edf3meshPrefsTb4b4b4.Te6edf3setDeviceAddressTb4b4b4(Te6edf3deviceAddrTb4b4b4)
Te6edf3nodeManagerTb4b4b4.Te6edf3clearTb4b4b4(Tb4b4b4)
Te6edf3messageProcessorTb4b4b4.Te6edf3valueTb4b4b4.Te6edf3clearEarlyPacketsTb4b4b4(Tb4b4b4)
Te6edf3databaseManagerTb4b4b4.Te6edf3switchActiveDatabaseTb4b4b4(Te6edf3deviceAddrTb4b4b4)
Te6edf3notificationManagerTb4b4b4.Te6edf3cancelAllTb4b4b4(Tb4b4b4)
Te6edf3nodeManagerTb4b4b4.Te6edf3loadCachedNodeDBTb4b4b4(Tb4b4b4)
Tb4b4b4}
Tb4b4b4}
Tb4b4b4}
Served by rngit 1.5.2 - Generated in 0.08s